package org.swiftsuspenders.injectionresults
{
	import org.swiftsuspenders.Injector;

	
	
public class InjectSingletonResult extends InjectionResult
{

	public function InjectSingletonResult(responseType : Class)
	{
		m_responseType = responseType;
	}
	
	
	private var m_responseType : Class;
	
	private var m_response : Object;
	
	
	override public function getResponse(injector : Injector) : Object
	{
		return m_response ||= createResponse(injector);
	}

	override public function equals(otherResult : InjectionResult) : Boolean
	{
		if (otherResult == this)
		{
			return true;
		}
		if (!(otherResult is InjectSingletonResult))
		{
			return false;
		}
		var castedResult : InjectSingletonResult =  InjectSingletonResult(otherResult);
		return castedResult.m_response == m_response
				&& castedResult.m_responseType == m_responseType;
	}


	private function createResponse(injector : Injector) : Object
	{
		return injector.instantiate(m_responseType);
	}
	
}
}